package com.ch.mapstruct.conver;

import com.ch.mapstruct.beans.Apple;
import com.ch.mapstruct.beans.AppleDTO;
import com.ch.mapstruct.beans.Fruit;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author CH
 * @date 2021-09-23 14:35
 * @desc
 */
@Mapper
public interface AppleConvert {
    AppleConvert INSTANCE = Mappers.getMapper(AppleConvert.class);

    /**
     * 苹果 -> 水果
     *
     * @param apple Apple
     * @return Fruit
     */
    Fruit appleToFruit(Apple apple);

    /**
     * 水果 -> 苹果
     *
     * @param fruit Fruit
     * @return Apple
     */
    Apple fruitToApple(Fruit fruit);

    /**
     * 不同字段名 Apple -> AppleDTO
     * @param apple Apple
     * @return AppleDTO
     */
    @Mapping(source = "apple.name",target = "appleName")
    AppleDTO appleToAppleDTO(Apple apple);
}
